package correlation

import (
	"image/color"

	"gonum.org/v1/gonum/mat"
)

type myPalette struct {
}

func (p myPalette) Colors() []color.Color {
	var colors []color.Color

	// Количество цветов
	//numColors := 255 * 4

	// Генерация цветов от красного до серого
	alpha := uint8(255)
	//step := float64(255.0 / float64(numColors) / 4)
	for i := 0; i < 255; i++ {
		r := uint8(255)
		g := uint8(i)
		b := uint8(0)
		colors = append(colors, color.NRGBA{r, g, b, alpha})
	}
	for i := 0; i < 255; i++ {
		r := uint8(255)
		g := uint8(255)
		b := uint8(i)
		colors = append(colors, color.NRGBA{r, g, b, alpha})
	}
	rColors := make([]color.Color, len(colors))
	for i, j := 0, len(colors)-1; i < j; i, j = i+1, j-1 {
		rColors[i], rColors[j] = colors[j], colors[i]
	}

	colors = append(colors, rColors...)

	return colors
}

type myGridXYZ struct {
	matrix mat.SymDense
}

func NewMyGridXYZ(m mat.SymDense) *myGridXYZ {
	return &myGridXYZ{
		matrix: m,
	}
}

func (grid *myGridXYZ) Dims() (x, y int) {
	return grid.matrix.RawSymmetric().N, grid.matrix.RawSymmetric().N
}

func (grid *myGridXYZ) X(x int) float64 {
	return float64(x)
}

func (grid *myGridXYZ) Y(y int) float64 {
	return float64(grid.matrix.RawSymmetric().N - 1 - y)
}

func (grid *myGridXYZ) Z(x, y int) float64 {
	return grid.matrix.At(x, y)
}

func (grid *myGridXYZ) Min() float64 {
	return -1.
}

func (grid *myGridXYZ) Max() float64 {
	return 1.
}
